home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / html / EscapeUtils.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  3.7 KB  |  94 lines

  1. /****i* SOURCE_FILE/INFO
  2. *
  3. * NAME
  4. *  EscapeUtils.js
  5. *
  6. * USAGE
  7. *  Part of Netobjects JavaScript Library.
  8. *
  9. * COPYRIGHT
  10. *  Copyright ⌐ 2002-2005 Website Pros, Inc.
  11. *  All Rights Reserved.
  12. *
  13. *  This is an unpublished work protected by Website Pros, Inc.
  14. *  as a trade secret, and is not to be used or disclosed except as
  15. *  expressly provided in a written license agreement executed by
  16. *  you and Website Pros, Inc.
  17. *
  18. *      <copyright@websitepros.com>
  19. *
  20. * NOTES
  21. *  JavaScript code.
  22. *****/
  23.  
  24. if (!IS.isModuleInitialized("IS.NOF.HTML.EscapeUtils"))
  25. {   
  26.     /****h* NOF_JavaScript_Library/NOF.HTML.EscapeUtils
  27.         *
  28.         * NAME
  29.         *  NOF.HTML.EscapeUtils
  30.         *
  31.         * DESCRIPTION
  32.         * 
  33.         *
  34.         * External dependencies: 
  35.         ****/  
  36.     
  37.     function NOF_EscapeUtils(content){
  38.         var escapeCharsHash  = [ "/", "=", "\\r", "\\n", '"',"&","<",">"];
  39.         var escapedCharsHash = ['/', '=', ' ', ' ', '"','&','<','>'];
  40.         
  41.         /*
  42.         // "⌐","«","┤","½","╗","í", "┐", "└","α","┴","ß","┬","Γ","├","π","─","Σ","┼","σ","╞","µ",
  43.         // "╟","τ","╨","≡", "╚","Φ","╔","Θ","╩", "Ω","╦","δ","╠","∞","═","φ","╬","ε","╧","∩","╤","±",
  44.         //  "╥","≥","╙","≤","╘","⌠","╒","⌡","╓","÷", "╪","°","┘", "∙","┌","·","█","√","▄","ⁿ","▌","²"," "
  45.         //"▐","■","▀","º","╢","╡","ª","▒","╖","¿","╕", "¬","║","¼","¡","»","░","╣","▓","│","╝","╜","╛","╫",
  46.         //"≈","ó","ú","ñ","Ñ"
  47.         var escapedCharsCodeHash = ['©','<SUP>®</SUP>','´','«', '»',
  48.             '¡','¿','À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å',
  49.             'Æ','æ','Ç','ç','Ð',
  50.             'ð','È','è','É','é',
  51.             'Ê','ê','Ë','ë','Ì','ì','Í','í','Î',
  52.             'î','Ï','ï','Ñ','ñ','Ò','ò',
  53.             'Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø',
  54.             'Ù','ù','Ú','ú','Û','û','Ü','ü','Ý',
  55.             'ý','ÿ','Þ','þ','ß','§','¶','µ','¦','±','·','¨',
  56.             '¸','ª','º','¬','­','¯','°','¹','²','³','¼','½','¾',
  57.             '×','÷','¢','£','¤','¥'
  58.             ];      
  59.         var escapeCharsCodeHash = [169, 174, 180, 171, 187, 161, 191,192, 224, 193, 225, 194, 226, 195, 227,
  60.             196, 228, 197, 229,198,230, 199, 231, 208, 240, 200,232,201,233,202,234,203,235,204,236,205,237,206,238,207,239,
  61.             209, 241, 210, 242, 211, 243, 212, 244, 213, 245, 214, 246, 216, 248, 217, 249, 218, 250, 219, 251, 220, 252, 221,253,255,
  62.             222, 254, 223, 167, 182, 181, 166, 177, 183, 168, 184, 170, 186, 172, 173, 175, 176, 185,178, 178,188, 189,190,215,
  63.             247, 162, 163,164,165 ];
  64.             for (var i=0;i<escapeCharsCodeHash.length;i++) {
  65.             var escapeCodeChar = escapeCharsCodeHash[i];
  66.             re = eval ("\/" + String.fromCharCode(escapeCodeChar) + "\/g;");
  67.             content = content.replace (re, escapedCharsCodeHash[i]);
  68.             }
  69.         */
  70.         
  71.         //replace any group '&#' by codifying each char
  72.         var re = /\&\#/g;
  73.         content = content.replace (re, "&#");
  74.         
  75.         for (var i=0;i<escapeCharsHash.length;i++) {
  76.             var escapeChar = escapeCharsHash[i];
  77.             re = eval ("\/" + escapeChar + "\/g;");
  78.             content.replace (re, escapedCharsHash[i]);
  79.         }
  80.         for (var i =0;i<content.length;i++) {
  81.             var ch = content.charAt(i);
  82.             var code = content.charCodeAt(i);
  83.             if (code > 127) {
  84.                 var re = eval ("\/" + ch + "\/g;");
  85.                 content = content.replace (re,"&#" + code + ";");
  86.             }
  87.         }
  88.         
  89.         return content;
  90.     }
  91.     
  92.     NOF.HTML.__proto__.EscapeUtils = NOF_EscapeUtils;    
  93. }      
  94.